package com.hzhr.iot.user.dao.helper;

import com.hzhr.iot.core.constant.CommonOptions;
import com.hzhr.iot.user.dao.DeptDao;
import com.hzhr.iot.user.entity.DeptEntity;
import com.hzhr.iot.user.queryModel.custom.DeptCustomQueryModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Component
public class DeptDaoHelper {
    @Autowired
    DeptDao deptDao;

    public DeptEntity getByIdAndResourceCode(int id, String resourceCode) {
        if (resourceCode == null) return null;
        DeptCustomQueryModel deptCustomQueryModel = new DeptCustomQueryModel();
        deptCustomQueryModel.setEqual_id(id);
        deptCustomQueryModel.setLike_resourceCode(resourceCode + "%");
        deptCustomQueryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        deptCustomQueryModel.setShow(true);
        DeptEntity deptEntity = deptDao.selectEntity(deptCustomQueryModel);
        return deptEntity;
    }

    public int getCountByParentIdAndName(int parentId, String name) {
        if (name == null) return 0;
        DeptCustomQueryModel deptCustomQueryModel = new DeptCustomQueryModel();
        deptCustomQueryModel.setEqual_parentId(parentId);
        deptCustomQueryModel.setEqual_name(name);
        deptCustomQueryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        int count = deptDao.selectCount(deptCustomQueryModel);
        return count;
    }

    public int getCountByParentId(int parentId) {
        DeptCustomQueryModel deptCustomQueryModel = new DeptCustomQueryModel();
        deptCustomQueryModel.setEqual_parentId(parentId);
        deptCustomQueryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        int count = deptDao.selectCount(deptCustomQueryModel);
        return count;
    }

    public DeptEntity getByParentIdAndOrderByCode(int parentId, String orderBy_code, int page, int count) {
        DeptCustomQueryModel deptCustomQueryModel = new DeptCustomQueryModel();
        deptCustomQueryModel.setEqual_parentId(parentId);
        deptCustomQueryModel.setPage(page, count);
        deptCustomQueryModel.setOrderBy_code(orderBy_code);
        deptCustomQueryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        deptCustomQueryModel.setShow(true);
        DeptEntity deptEntity = deptDao.selectEntity(deptCustomQueryModel);
        return deptEntity;
    }

    public DeptEntity getByCode(String code) {
        if (code == null) return null;
        DeptCustomQueryModel deptCustomQueryModel = new DeptCustomQueryModel();
        deptCustomQueryModel.setEqual_code(code);
        deptCustomQueryModel.setEqual_isValid(CommonOptions.YES_NO.YES);
        deptCustomQueryModel.setShow(true);
        DeptEntity deptEntity = deptDao.selectEntity(deptCustomQueryModel);
        return deptEntity;
    }
}
